import mongoose from 'mongoose'

const User = mongoose.model('User')
const ObjectId = mongoose.Types.ObjectId

export async function updateSocketIdById(id, socketId) {
  await User.updateOne({
    _id: ObjectId(id)
  }, {
    $set: {
      socketId,
      onLine: true
    }
  })
}

export async function getSocketIdByUserId(id) {
  return await User.findOne({
    _id: ObjectId(id)
  })
}

export async function socketLogout(id) {
  await User.updateOne({
    _id: ObjectId(id)
  }, {
    $set: {
      onLine: false
    }
  })
}
